package cn.gogpay.dcb.api.web;

import cn.gogpay.dcb.api.service.OutService;
import cn.gogpay.dcb.api.web.base.BaseController;
import cn.gogpay.dcb.api.web.form.CountForm;
import cn.gogpay.dcb.api.web.form.NotifyForm;
import cn.gogpay.dcb.common.dto.ResultDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 说明
 *
 * @author jiaoming@gogpay.cn
 * @date 2019/11/22 18:45
 */
@RequestMapping("/apiOut/count/")
@Controller
public class OutController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(OutController.class);

    @Autowired
    private OutService outService;

    @ResponseBody
    @PostMapping("/isHaveCount")
    public ResultDTO isHaveCount(@RequestBody CountForm form) {
        logger.info("[免费乘公交][是否可以免费][form][{}]", form);
        ResultDTO haveCount = outService.isHaveCount(form);
        logger.info("[免费乘公交][是否可以免费][form][{}][result][{}]", form, haveCount);
        return haveCount;
    }

    @ResponseBody
    @PostMapping("/notify")
    public ResultDTO pay(@RequestBody NotifyForm form) {
        logger.info("[免费乘公交][回调通知][form][{}]", form);
        ResultDTO haveCount = outService.pullNotify(form);
        logger.info("[免费乘公交][回调通知][form][{}][result][{}]", form, haveCount);
        return haveCount;
    }


}
